. "$(dirname -- "$0")/log.sh"

# 禁止合并的分支
FORBIDDEN_CHECKOUT_BRANCHES=("test" "pre" "develop")

getBranchName() { 
    echo $(git rev-parse --abbrev-ref HEAD) 
} 

getMergedBranches() { 
    eval names=($(git branch --merged))
    lastIndex=$((${#names[@]}-1))
    echo  ${names[lastIndex]}
} 

valideCanCheckout() {
    if [ "$(getBranchName)" != "$1" ]; then 
        if [[ $(getMergedBranches) == "$1" ]]; then 
        error "Don't create branches from the $1 branch!" 
        exit 1 
        fi 
    fi 
}

for branchName in $FORBIDDEN_CHECKOUT_BRANCHES  
do
   valideCanCheckout $branchName 
done